package chapter21.homework02;

import java.util.ArrayList;

//存储多个状态信息，选择性回档
public class Caretaker {
    ArrayList<Memento> mementoArrayList;

    public Caretaker() {
        this.mementoArrayList = new ArrayList<>();
    }

    public void add(Memento memento){
        mementoArrayList.add(memento);
    }

    public void remove(Memento memento){
        mementoArrayList.remove(memento);
    }
    //判断状态是否存在
    public Memento getMemento(int index) {
        return -1<index&&index<mementoArrayList.size()?mementoArrayList.get(index):null;
    }
}
